$(document).ready(function(){
	//获取标签名称
	$('.js-tagnames').each(function(){
		var _this = $(this);
		var userId = _this.parent('tr').attr('dataid');
		$.ajax({
			type : "GET",
			url : '/users/'+userId+'/tags',
			beforeSend : function(xhr) {
				_this.html('正在加载...');
			},
			error : function(xhr, status) {
				 _this.html("加载失败！");
			},
			success : function(data) {
				_this.html('');
		       if(data && data.length > 0){
		    	  $.each(data,function(i,item){
		    		  _this.append('<span style="margin-left: 3px; padding:0px 5px;border-style: groove;">'+item.name+'</span>');
		    	  });
		       }
			}
		});
	});
	//操作列
	$('.js-oper').change(function(){
		var _this = $(this);
		var userId = _this.attr('dataid');
		if(_this.val()=='1'){//修改
			window.location.href='/users/'+userId+'/edit';
			return false;
		}else if(_this.val()=='2'){//删除
			if(confirm("确定要将["+_this.attr('username')+"]置为离职？")){
				$.ajax({
					type : "POST",
					url : '/users/'+userId+'/delete',
					data:"_method=delete",
					beforeSend : function(xhr) {
						showMsg('正在操作……');
					},
					error : function(xhr, status) {
						 hideMsg();
						 alert("操作失败！");
					},
					success : function(data) {
						 hideMsg();
				       if(data && data == true){
				    	   alert("操作成功！");
				    	   window.location.reload();
				       }else{
				    	   alert(data);
				       }
					}
				});
			}
		}
		return false;
	});

});